﻿/// <reference path="jquery-1.5.1.js" />
/// <reference path="jquery-1.5.1-vsdoc.js" />
function ShowCenteredPopUp(pageURL, windowName, width, height, isScrolling) {
    //alert(pageURL);
    var scrollbars = isScrolling ? 'yes' : 'no';    
    var leftPosition = (screen.width) ? (screen.width - width) / 2 : 0;
    var topPosition = (screen.height) ? (screen.height - height) / 2 : 0;
    topPosition -= 30;
    var settings = 'height=' + height + ',width=' + width + ',top=' + topPosition + ',left=' + leftPosition + ',resizable=no,scrollbars=' + scrollbars + ',menubar=no,toolbar=no,status=yes,location=no,directories=no,addressbar=no'
    var page = pageURL;
    win = window.open(page, windowName, settings);
    if (win != null) {
        win.window.focus();
    }
    return win;
}
function RemoveFromCompareList(productID, element) {
    $.ajax({
        type: 'POST',
        url: '/Ajax/RemoveProductToCompare',
        data: 'productID=' + productID,
        success: function (result) {
            if (result == 1) {
                $(element).parent().parent().slideUp('slow', function () { $(this).remove(); RebindCompareAllLink(); });                
            }
        }
    });
}
function AddToProductCompare(productID, element) {
    $.ajax({
        type: 'POST',
        url: '/Ajax/AddProductToCompare',
        data: 'productID=' + productID,
        success: function (result) {
            if (result.length > 0) {
                var product = eval('(' + result + ')');
                var html = '<tr><td>';
                if (product.ProductImages.length > 0) {
                    html += '<img class="product-img" src="/UploadedImages/ProductImages/' + product.ProductImages[0].Thumbnail + '" alt="' + product.Name + ' title="' + product.Name + '" />';
                }
                html += '<input type="hidden" name="hdnCompareProductID" value="' + product.ID + '" />';
                html += '</td>';
                html += '<td><a href="/product/details/' + product.ID + '/' + product.ProductUrl + '" target="_blank">' + product.Name + '</a></td>';
                html += '<td><a href="javascript:void(0);" onclick="RemoveFromCompareList(' + product.ID + ', this);">Del</a></td>';
                html += '</tr>';
                $('#tblProductCompareList').append(html);
                RebindCompareAllLink();
                $(element).parent().prepend('<span class="product-compared-link-button">Compared</span>');
                $(element).remove(); //.html("Compared").removeClass('product-compare-link-button').addClass('product-compared-link-button');
            }
        }
    });
}
//Bind Compare List
$(document).ready(function () {
    var divCompare = $('#divProductCompareList');
    $('.product-compare-link-button, .product-compared-link-button').each(function () {
        $(this).hover(function (e) {
            var position = $(this).position();
            $(divCompare).css('top', position.top + 23).css('left', position.left).show();
            e.stopPropagation();
        });
    });

    $(document).mouseover(function () {
        $(divCompare).hide();
    });
    $(divCompare).mouseover(function (e) {
        e.stopPropagation();
    });
});
function RebindCompareAllLink() {
    var ids = '';
    $('#tblProductCompareList input[name=hdnCompareProductID]').each(function () {
        if (ids.length == 0)
            ids = $(this).val();
        else
            ids += ',' + $(this).val();
    });
    $('#aCompareAll').attr('href', '/product/compare/' + ids);
}
function GoComparePage() {
    window.location = $('#aCompareAll').attr('href');
}